package org.eenie.appseed.ui.main

import androidx.recyclerview.widget.LinearLayoutManager
import com.afollestad.recyclical.datasource.dataSourceOf
import com.afollestad.recyclical.setup
import com.afollestad.recyclical.withItem
import org.eenie.appseed.R
import org.eenie.appseed.databinding.ActivityMainBinding
import org.eenie.appseed.databinding.ItemNavOptionBinding
import org.eenie.appseed.ui.bento.BentoActivity
import org.eenie.appseed.ui.boost.FlutterBoostDemoActivity
import org.eenie.appseed.ui.caution.CautionActivity
import org.eenie.appseed.ui.chat.ChatActivity
import org.eenie.appseed.ui.compose.ComposeDemoActivity
import org.eenie.appseed.ui.concatadapter.ConcatAdapterActivity
import org.eenie.appseed.ui.counter.CounterActivity
import org.eenie.appseed.ui.crash.CrashActivity
import org.eenie.appseed.ui.dialog.DialogDemoActivity
import org.eenie.appseed.ui.form.FormActivity
import org.eenie.appseed.ui.logcat.LogcatActivity
import org.eenie.core.base.viewbinding.BaseBindingActivity
import org.eenie.core.ext.startTargetActivity


class MainActivity : BaseBindingActivity<ActivityMainBinding>() {


    private val datas = dataSourceOf(
        NavOption("计数器", "计数器", "演示ViewModel计数能力", CounterActivity::class.java),
        NavOption("崩溃日志", "崩溃日志", "演示崩溃日志捕获能力", CrashActivity::class.java),
        NavOption("网络", "网络", "演示网络api使用", FormActivity::class.java),
        NavOption("RIVE", "动画RIVE", "演示rive的使用", CautionActivity::class.java),
        NavOption("日志", "日志Logcat", "logcat捕捉", LogcatActivity::class.java),
        NavOption("混合", "混合Flutter-咸鱼框架", "flutter boost demo", FlutterBoostDemoActivity::class.java),
        NavOption("Compose", "Compose", "compose demo", ComposeDemoActivity::class.java),
        NavOption("IM", "IM", "聊天界面的实现", ChatActivity::class.java),
        NavOption("弹窗", "弹窗", "弹窗演示", DialogDemoActivity::class.java),
        NavOption("Bento", "bento", "bento演示", BentoActivity::class.java),
        NavOption("ConcatAdapter", "ConcatAdapter", "ConcatAdapter演示", ConcatAdapterActivity::class.java),
    )

    override fun providerBinding() = ActivityMainBinding.inflate(layoutInflater)

    override fun initUI() {
        binding.rvOption.setup {
            withLayoutManager(LinearLayoutManager(mContext))
            withDataSource(datas)

            withItem<NavOption, BindingViewHolder>(R.layout.item_nav_option) {

                onBind(::BindingViewHolder) { _, item ->
                    run {
                        val binding = binding<ItemNavOptionBinding>()
                        binding.tvNav.text = item.name
                        binding.tvTitle.text = item.title
                        binding.tvDesc.text = item.desc
                    }
                }

                onClick {
                    startTargetActivity(item.target)

                }

            }
        }


    }


}